#! /usr/bin/env python

import os
import time

# get file list
files = os.popen('ls /proc/ring')
fns = list() # file names
for fn in files:
    fns.append(fn.strip())

# open files to save results
fl = list();
for fn in fns:
    fl.append(open(fn+'.txt', "w"))

# start iperf here
os.system('ssh solon@10.21.5.201 /home/solon/sending.sh')
# log /proc/ring/
nextStart = start = time.time()
for i in range(100):
    for j in range(100):
        for i, fn in enumerate(fns):
            #print 'cat /proc/ring/'+f
            domain = open('/proc/ring/'+fn)
            fl[i].write(domain.next())
        nextStart += 0.01
        duration = nextStart-time.time()
        if duration < 0:
            duration = 0
        time.sleep(duration)
stop = time.time()
print 'execuation time', stop - start
for f in fl:
    f.close()
